#ifndef HOSTLIST_H
#define HOSTLIST_H

#include <QAbstractListModel>
#include <QList>
#include <QString>
#include <QHash>
#include <QByteArray>
#include <QDateTime>

class Host
{
public:

    Host(QString name_, QString hostip_,int hostprot_=8234,  QString protocol_="HJ212_2017", QString color_="gray"){
        HostName = name_;
        HostIp=hostip_;
        HostPort=hostprot_;
        protocol=protocol_;
        colorCode = color_;
    }
public:
    QString HostName;
    QString HostIp;
    int HostPort;
    QString protocol;
    QString colorCode;
    QString dataString;
};

class HostList : public QAbstractListModel
{

    Q_OBJECT

public:
//    QString name;
//    QString portname;
//    QString protocol;
//    int comaddr;
//    QString colorCode;
    enum LineInfo_Roles{
        RoleName =Qt::UserRole + 1,
        RoleHostIp,
        RoleHostPort,
        RoleProtocol,
        RolecolorCode,
        RoledataString
    };


public:
    explicit HostList(QObject *parent = 0);

    int rowCount(const QModelIndex &parent) const;
    int rowCountRead();
    QVariant data(const QModelIndex &index, int role) const;
    QHash<int, QByteArray> roleNames() const;
    Q_INVOKABLE void addHost(QString name_, QString hostip_, QString hostprot_, QString protocol_);
    QList<Host> getdata(){return m_display_list;}
    //void setdata(QList<Device>){}
    void changeDataString(int index,QString str);
    Q_INVOKABLE void changeName(int index);
    Q_INVOKABLE void clickItem(int index);

signals:
    void dataChanged();
public slots:

private:
    QList<Host> m_display_list;
    QHash<int, QByteArray> m_roleNames;
};

#endif // HOSTLIST_H
